/**
 * Copyright 2013 Net355 Co,.Ltd. 
 * All rights reserved.
 *
 * "DataHelper.java is for what: "
 * 
 * Create by Ray at 2013-12-25 上午11:49:30.
 * Ray [email:rayinhangzhou@126.com]
 * 
 * Revision History
 *
 * Date            Programmer                   Notes
 * ---------    ---------------------  -----------------------------------
 * 2013-12-25            Ray                       initial
 **/


package com.net355.eblog.util;

import java.util.ArrayList;
import java.util.List;

import com.net355.eblog.models.EbChat;

public class DataHelper {


	public static List<EbChat> getChatListByNote(String noteGuid, int offset, int size) {
		List<EbChat> items = new ArrayList<EbChat>();
		List<?> chats = (List<?>) CacheHelper.get_cache(noteGuid+GlobalParams.CACHE_NAME_LIST_NOTE_COMMENT);
		if(chats==null) {
			return items;
		}
		int step = 0;
		int total = chats.size();
		int index = offset + step;
		while (step < size && index < total) {
			EbChat chat = (EbChat) CacheHelper.get_cache((String) chats.get(index));
			if(!StringUtil.isEmpty(chat.getFatherGuid())) {
				chat.setFatherChat((EbChat)CacheHelper.get_cache(chat.getFatherGuid()));
			}
			items.add(chat);
			step++; 
			index++;
		}
		return items;
	}
	
	public static List<EbChat> getChatList(int offset, int size) {
		List<EbChat> items = new ArrayList<EbChat>();
		List<?> chats = (List<?>) CacheHelper.get_cache(GlobalParams.CACHE_NAME_LIST_CHAT_SYSTEM);
		if(chats==null || chats.size()==0) {
			return items;
		}
		int step = 0;
		int total = chats.size();
		int index = offset + step;
		while (step < size && index < total) {
			EbChat chat = (EbChat) CacheHelper.get_cache((String) chats.get(index));
			if(!StringUtil.isEmpty(chat.getFatherGuid())) {
				chat.setFatherChat((EbChat)CacheHelper.get_cache(chat.getFatherGuid()));
			}
			items.add(chat);
			step++; 
			index++;
		}
		return items;
	}
}
